# -*- coding: utf-8 -*-
# @Time    : 2016-12-07 10:46
# @Author  : wzb<wangzhibin_x@foxmail.com>
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import csv
import pandas
import seaborn
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import math
from matplotlib.pyplot import MultipleLocator


filename='testdata/vol1_new.txt'
filename2='testdata/vol2_new2.txt'
filename3='testdata/vol3_new.txt'

filename4='testdata/adc7.6.2.txt'
my_matrix = np.loadtxt(open(filename,"rb"),delimiter=",",skiprows=0)

my_matrix2 = np.loadtxt(open(filename2,"rb"),delimiter=",",skiprows=0)
my_matrix3 = np.loadtxt(open(filename3,"rb"),delimiter=",",skiprows=0)
my_matrix4 = np.loadtxt(open(filename4,"rb"),delimiter=",",skiprows=0)
x=my_matrix[:,1]
y=my_matrix[:,0]


x2=my_matrix2[:,1]
y2=my_matrix2[:,0]

x3=my_matrix3[:,1]
y3=my_matrix3[:,0]


#x4=my_matrix4[:,1]
#y4=my_matrix4[:,0]

x4=(np.array(x)+np.array(x2)+np.array(x3))/3
y4=y3

fileall=open('testdata/adcall2.txt','w')
for i in range(len(y4)):
    fileall.write('{:},{:}\n'.format(int(y4[i]*1000), int(round(x4[i],0))))
fileall.close()
fig=plt.figure(figsize=(8,4))





print("################################################")

#plt.plot(t, y, label="$a-y$",color="black",linewidth=0.5)
#plt.plot(t, x, label="$a-x$",color="blue",linewidth=0.5)
#plt.plot(t, z, label="$a-z$",color="green",linewidth=0.5)
#plt.plot(t, my_matrix[:,4], label="$gyr-x$",color="y",linewidth=1)
#plt.plot(t, my_matrix[:,5], label="$gyr-y$",color="c",linewidth=1)
#plt.plot(t, my_matrix[:,6], label="$gyr-z$",color="b",linewidth=1)
#plt.plot(test_data[:,0],test_data[:,1] , label="$track$",color="red",linewidth=1)

#plt.plot(testx,testy , label="$track1$",color="blue",linewidth=1)
#qiaodan
#plt.plot(test_data[:,0][0:50],test_data[:,1][0:50] , label="$track$",color="blue",linewidth=1)
#plt.plot(test_data[:,0][50:100],test_data[:,1][50:100] , label="$track$",color="red",linewidth=1)
#plt.plot(test_data[:,0][100:150],test_data[:,1][100:150] , label="$track$",color="green",linewidth=1)
#plt.plot(test_data[:,0][150:200],test_data[:,1][150:200] , label="$track$",color="y",linewidth=1)
#end
axl = fig.add_subplot(111)
axl.scatter(x/1000000,y,s=1,c='r',marker='o')

ax2 = fig.add_subplot(111)
ax2.scatter(x2/1000000,y2,s=1,c='r',marker='o')

ax3 = fig.add_subplot(111)
ax3.scatter(x3/1000000,y3,s=1,c='r',marker='o')

ax4 = fig.add_subplot(111)
ax4.scatter(x4/1000000,y4,s=1,c='r',marker='o')

plt.plot(x/1000000, y, label="$U-adc1$",color="red",linewidth=0.5)
plt.plot(x2/1000000, y2, label="$U-adc2$",color="blue",linewidth=0.5)
plt.plot(x3/1000000, y3, label="$U-adc3$",color="green",linewidth=0.5)

plt.plot(x4/1000000, y4, label="$U-adc4$",color="black",linewidth=1.0)
#x_major_locator=MultipleLocator(1)
x_major_locator=MultipleLocator(0.1)
#把x轴的刻度间隔设置为1，并存在变量里
#y_major_locator=MultipleLocator(10)
y_major_locator=MultipleLocator(0.5)
#把y轴的刻度间隔设置为10，并存在变量里
ax=plt.gca()
#ax为两条坐标轴的实例
ax.xaxis.set_major_locator(x_major_locator)
#把x轴的主刻度设置为1的倍数
ax.yaxis.set_major_locator(y_major_locator)
#把y轴的主刻度设置为10的倍数
plt.xlim(1.1,2.6)
#把x轴的刻度范围设置为-0.5到11，因为0.5不满一个刻度间隔，所以数字不会显示出来，但是能看到一点空白
plt.ylim(40,90)
#把y轴的刻度范围设置为-5到110，同理，-5不会标出来，但是能看到一点空白



plt.xlabel("adc")
plt.ylabel("U")
plt.title(filename)
#plt.ylim(-20, 20)


#plt.xlabel(x/1000000)
#plt.xticks(range(0,88))
#plt.yticks(range((int)(min(y)),(int)(max(y))))

plt.legend()
plt.show()









